package com.hwz.hwzliving.commodity.service.impl;

import com.hwz.hwzliving.commodity.dao.BrandDao;
import com.hwz.hwzliving.commodity.dao.CategoryDao;
import com.hwz.hwzliving.commodity.entity.BrandEntity;
import com.hwz.hwzliving.commodity.entity.CategoryEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwz.common.utils.PageUtils;
import com.hwz.common.utils.Query;

import com.hwz.hwzliving.commodity.dao.CategoryBrandRelationDao;
import com.hwz.hwzliving.commodity.entity.CategoryBrandRelationEntity;
import com.hwz.hwzliving.commodity.service.CategoryBrandRelationService;

import javax.annotation.Resource;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CategoryBrandRelationEntity> page = this.page(
                new Query<CategoryBrandRelationEntity>().getPage(params),
                new QueryWrapper<CategoryBrandRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Resource
    BrandDao brandDao;
    @Resource
    CategoryDao categoryDao;

    @Override
    public void saveAll(CategoryBrandRelationEntity categoryBrandRelation) {
//        通过id获取品牌和分类信息对象
        BrandEntity brandEntity = brandDao.selectById(categoryBrandRelation.getBrandId());
        CategoryEntity categoryEntity = categoryDao.selectById(categoryBrandRelation.getCategoryId());
        //设置名字信息给需要保存的对象
        categoryBrandRelation.setBrandName(brandEntity.getName());
        categoryBrandRelation.setCategoryName(categoryEntity.getName());
        this.save(categoryBrandRelation);
    }


}